#Include g:\AHK\git-ahk-lib\util\event\MouseEvent.ahk
#Include G:\AHK\git-ahk-lib\lib\directOverlay\ShinsOverlayClass.ahk

Esc:: ExitApp()

#Include Radio.ahk
#Include RadioGroup.ahk
#Include Button.ahk

bx := (A_ScreenWidth - 600) // 2, by := (A_ScreenHeight - 500) // 2, bw := 600, bh := 500
overlay := ShinsOverlayClass(bx, by, bw, bh, 1, 0, 0)

c := '0x000000', c2 := '0x00AAAA', c3 := '0x255e90'
red := '0xe96464', green := '0x22ff00'
w := 30, h := 30

titleBar := Rect(0, 0, bw - w, h)
closeBtn := Button(Rect(titleBar.w, 0, w, h), c, red)
closeBtn.OnEvent(Button.ON_RELEASE, (*) => ExitApp())

me := MouseEvent(overlay.gui.Hwnd)
me.Register(MouseEvent.Events.LBUTTON_UP, OnLU)
me.Register(MouseEvent.Events.LBUTTON_DOWN, OnLD)
me.RegisterOnCondition(MouseEvent.Events.LBUTTON_DOWN,
  (point, *) => point.InRect(titleBar),
  MoveWin)


group := RadioGroup(Rect(51, 50, w * 3, h))
group.AddRadios(
  Radio(Rect(0, 0, w, h), c, c2, c3),
  Radio(Rect(30, 0, w, h), c, c2, c3, 1),
  Radio(Rect(60, 0, w, h), c, c2, c3)
)

btn0 := Button(Rect(51, 90, w, h), c2, c3)


Refresh()

DrawBase() {
  overlay.FillRectangle(0, 0, bw, bh, '0xff0f4747')
  overlay.FillRectangle(0, 0, titleBar.w, titleBar.h, '0x297e86')
  overlay.DrawText('All-test', 10, 0, , green, , 'aMid w100 h' titleBar.h)
  closeBtn.Draw(overlay)
  overlay.FillCircle(closeBtn._rect.x + closeBtn._rect.w // 2, h // 2, 5, c2)
  overlay.DrawRectangle(1, 1, bw - 1, bh - 1, c3)
}

DrawCtrl() {
  group.Draw(overlay)
  btn0.Draw(overlay)
}


OnLU(point, *) {
  group.OnLU(point)
  btn0.OnRelease(point.InRect(btn0._rect))
  closeBtn.OnRelease(point.InRect(closeBtn._rect))
  Refresh()
}

OnLD(point, *) {
  group.OnLD(point)
  if point.InRect(btn0._rect)
    btn0.OnPressed()
  else if point.InRect(closeBtn._rect)
    closeBtn.OnPressed()
  Refresh()
}

MoveWin(*) {
  CoordMode "Mouse", "Screen"
  MouseGetPos(&px, &py), overlay.gui.GetPos(&wx, &wy)
  dx := wx - px, dy := wy - py
  While GetKeyState("LButton", "P") {
    MouseGetPos(&nx, &ny)
    if nx = px and ny = py
      continue
    overlay.gui.Move(nx + dx, ny + dy)
    px := nx, py := ny
  }
}

Refresh() {
  overlay.BeginDraw()
  DrawBase()
  DrawCtrl()
  overlay.EndDraw()
}